package com.easylinkin.linkappapi.lobar.controller.app;


import com.easylinkin.linkappapi.lobar.dto.UserClockDTO;
import com.easylinkin.linkappapi.lobar.dto.app.LobarUserDTO;
import com.easylinkin.linkappapi.lobar.service.UserClockService;
import com.easylinkin.linkappapi.lobar.service.UserProjectService;
import com.easylinkin.linkappapi.security.context.LinkappUserContextProducer;
import io.swagger.annotations.Api;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author: kan yuanfeng
 * @Date: 2020/11/04 11:42
 * @Description: app端花名册
 */
@RestController
@RequestMapping("appUser")
@Api(tags = "app端花名册")
public class AppUserController {
  @Autowired
  private UserProjectService userProjectService;
  @Autowired
  private UserClockService userClockService;
  @Autowired
  private LinkappUserContextProducer linkappUserContextProducer;

  /**
   * app获取总人数和出勤率
   */
  @GetMapping("index")
  public RestMessage getSum(){
    String tenantId = linkappUserContextProducer.getNotNullCurrent().getTenantId();
    LobarUserDTO lobarUserDTO = userProjectService.getSum(tenantId);
    return RestBuilders.successBuilder().data(lobarUserDTO).build();
  }

  /**
   * 最近5次考勤
   */
  @GetMapping("userClock")
  public RestMessage getUserClock(){
    List<UserClockDTO> userClockDTOS = userClockService.findLastFive();
    return RestBuilders.successBuilder().data(userClockDTOS).build();
  }

  /**
   * 获取工种考勤率
   */
  @GetMapping("workType")
  public RestMessage getByWorkType(String workType){
    //分为两个分类
    if ("作业人员".equals(workType)){
      Map<String, List<LobarUserDTO>> result = userProjectService.getBy3WorkType(workType);
      return RestBuilders.successBuilder().data(result).build();
    }else {
      List<LobarUserDTO> result2 = userProjectService.getBy2WorkType(workType);
      return RestBuilders.successBuilder().data(result2).build();
    }

  }
}
